package com.cc.eb.config;

import com.cc.eb.mapper.EbProductCategoryMapper;
import com.cc.eb.model.EbProductCategory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import java.util.List;

/**
 * @Description: 用一句话描述
 * @Auther: 新梦想*陈超
 * @Date: 2022/1/7 14:27
 */
@Component
public class InitContext implements CommandLineRunner {

    @Resource
    private EbProductCategoryMapper ebProductCategoryMapper;

    @Resource
    private ServletContext  application;

    @Override
    public void run(String... args) throws Exception {
        System.out.println("======spring  boot项目自定义初始化 ====");
        //1.查询 所有大类 和小类
        List<EbProductCategory> bigs = ebProductCategoryMapper.selectBigCategory();
        List<EbProductCategory> smalls = ebProductCategoryMapper.selectSmallCategory();

        //2.放到全局的context域中
        application.setAttribute("bigs",bigs);
        application.setAttribute("smalls",smalls);

    }
}
